package com.daohang361.imqq.pugin.encoder;

import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.encoder.InterfaceEncoder;
import com.daohang361.imqq.protocol.QQ2011;
import com.daohang361.imqq.tool.ByteArray;
import com.daohang361.imqq.tool.Hex2Bytes;
import com.daohang361.imqq.tool.MyByteSendArray;
import com.daohang361.imqq.tool.MyUtil;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-6-8 下午09:02:04 
 */
public class Encoder031C implements InterfaceEncoder{
	@Override
	public byte[] encode(QQUser myqq, int c) {
		ByteArray myByte = doHead(myqq, "031C");
//		myByte.putHex("0E 7E 0F 6E");
		myByte.putByte(myqq.getAttr("token_data_2E"));
		myByte.putHex("00 38");
		myByte.putByte(myqq.getAttr("token_data_d1"));
		myByte.saveThis();//保存此段作为第0段
	
			myByte.putHex(
					"00 00 FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01"+
					"00 60 00 60 00 00 FF DB 00 43 00 03 02 02 03 02"+
					"02 03 03 03 03 04 03 03 04 05 08 05 05 04 04 05"+
					"0A 07 07 06 08 0C 0A 0C 0C 0B 0A 0B 0B 0D 0E 12"+
					"10 0D 0E 11 0E 0B 0B 10 16 10 11 13 14 15 15 15"+
					"0C 0F 17 18 16 14 18 12 14 15 14 FF DB 00 43 01"+
					"03 04 04 05 04 05 09 05 05 09 14 0D 0B 0D 14 14"+
					"14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14"+
					"14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14"+
					"14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14"+
					"FF C0 00 11 08 00 55 01 04 03 01 22 00 02 11 01"+
					"03 11 01 FF C4 00 1F 00 00 01 05 01 01 01 01 01"+
					"01 00 00 00 00 00 00 00 00 01 02 03 04 05 06 07"+
					"08 09 0A 0B FF C4 00 B5 10 00 02 01 03 03 02 04"+
					"03 05 05 04 04 00 00 01 7D 01 02 03 00 04 11 05"+
					"12 21 31 41 06 13 51 61 07 22 71 14 32 81 91 A1"+
					"08 23 42 B1 C1 15 52 D1 F0 24 33 62 72 82 09 0A"+
					"16 17 18 19 1A 25 26 27 28 29 2A 34 35 36 37 38"+
					"39 3A 43 44 45 46 47 48 49 4A 53 54 55 56 57 58"+
					"59 5A 63 64 65 66 67 68 69 6A 73 74 75 76 77 78"+
					"79 7A 83 84 85 86 87 88 89 8A 92 93 94 95 96 97"+
					"98 99 9A A2 A3 A4 A5 A6 A7 A8 A9 AA B2 B3 B4 B5"+
					"B6 B7 B8 B9 BA C2 C3 C4 C5 C6 C7 C8 C9 CA D2 D3"+
					"D4 D5 D6 D7 D8 D9 DA E1 E2 E3 E4 E5 E6 E7 E8 E9"+
					"EA F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FF C4 00 1F 01"+
					"00 03 01 01 01 01 01 01 01 01 01 00 00 00 00 00"+
					"00 01 02 03 04 05 06 07 08 09 0A 0B FF C4 00 B5"+
					"11 00 02 01 02 04 04 03 04 07 05 04 04 00 01 02"+
					"77 00 01 02 03 11 04 05 21 31 06 12 41 51 07 61"+
					"71 13 22 32 81 08 14 42 91 A1 B1 C1 09 23 33 52"+
					"F0 15 62 72 D1 0A 16 24 34 E1 25 F1 17 18 19 1A"+
					"26 27 28 29 2A 35 36 37 38 39 3A 43 44 45 46 47"+
					"48 49 4A 53 54 55 56 57 58 59 5A 63 64 65 66 67"+
					"68 69 6A 73 74 75 76 77 78 79 7A 82 83 84 85 86"+
					"87 88 89 8A 92 93 94 95 96 97 98 99 9A A2 A3 A4"+
					"A5 A6 A7 A8 A9 AA B2 B3 B4 B5 B6 B7 B8 B9 BA C2"+
					"C3 C4 C5 C6 C7 C8 C9 CA D2 D3 D4 D5 D6 D7 D8 D9"+
					"DA E2 E3 E4 E5 E6 E7 E8 E9 EA F2 F3 F4 F5 F6 F7"+
					"F8 F9 FA FF DA 00 0C 03 01 00 02 11 03 11 00 3F"+
					"00 FD 1D A7 2D 36 9C BD 2B A9 98 B1 68 A2 8A 64"+
					"85 38 74 A6 D3 E8 00 A5 5E B4 94 AB 40 98 B4 51"+
					"45 04 8F A2 8A 28 00 A5 5E B4 94 AB 40 31 D4 AB"+
					"49 4A BD 28 06 2D 3C 74 A6 53 C7 4A A2 40 75 A7"+
					"D3 47 5A 75 48 05 2A D2 52 81 40 0B 45 14      ");
		
		myByte.saveThis();//保存此段作为第一段
		System.out.println("imgKey:"+Hex2Bytes.bytesToHexString(myqq.getAttr("imgKey")));
		myByte.teaThis(1, 1,myqq.getAttr("imgKey"));//加密第一段到第一段
		doTail(myByte);
		return myByte.getByteList();//返回完整的package
	}
	
	private boolean ignore=false;
	@Override
	public byte[] encode(QQUser myqq, int c,Object...o) {
		System.out.println("使用默认编码器 命令为:"+MyUtil.intTo2Hex(c));
		ByteArray array=doHead(myqq,MyUtil.intTo2Hex(c));
		array.saveThis();//保存此段作为第0段
		array.putByte(myqq.getSend());
		array.saveThis();//保存此段作为第一段
		array.teaThis(1, 1,myqq.getAttr("SessionKey"));//加密第一段到第一段
		array=doTail(array);
		return array.getByteList();
	}

	public ByteArray doHead(QQUser myqq,String HexCommand)
	{
		ByteArray myByte = new MyByteSendArray();
		myByte.putHex("05");//05系列
		myByte.putInt(QQ2011.QQ_PROTOCOL_VERSION);
		myByte.putHex(HexCommand);
		myByte.putHex("00 32");
		myByte.putInt(myqq.getPakage());
		myByte.putInt(myqq.getQq());
		myByte.putHex("01 00 00 00 00 00 00 00");
		return myByte;
	}
	public ByteArray doTail(ByteArray myByte)
	{
		myByte.putInt(QQ2011.QQ_PROTOCOL_PACKAGE_TAIL);
		myByte.saveThis();//保存此段作为第二段
		return myByte;//返回完整的package
	}
	
	@Override
	public boolean getIgnore() {
		
		return ignore;
	}
	
	@Override
	public void setIgnore(boolean ignore) {
		this.ignore=ignore;
	}
	@Override
	public Object invoke(Object... o) {
	return null;
	}
}
